package com.pai4j.log.entity;

import lombok.Data;
import org.hibernate.annotations.UuidGenerator;

import jakarta.persistence.*;
import java.util.Date;

/**
 * 操作日志实体类
 *
 * @author: CYM-pai
 * @date: 2025/07/29 15:15
 **/
@Data
@Entity
@Table(name = "pai4j_operation_log", indexes = {
        @Index(name = "idx_user_id", columnList = "userId"),
        @Index(name = "idx_module", columnList = "module"),
        @Index(name = "idx_operation", columnList = "operation"),
        @Index(name = "idx_create_time", columnList = "createTime"),
        @Index(name = "idx_trace_id", columnList = "traceId"),
        @Index(name = "idx_status", columnList = "status")
})
public class OperationLogEntity {

    /**
     * 主键ID
     */
    @Id
    @UuidGenerator
    @Column(name = "id", length = 64)
    private String id;

    /**
     * 链路追踪ID
     */
    @Column(name = "trace_id", length = 64)
    private String traceId;

    /**
     * 操作用户ID
     */
    @Column(name = "user_id", length = 64)
    private String userId;

    /**
     * 操作用户名
     */
    @Column(name = "user_name", length = 100)
    private String userName;

    /**
     * 模块名称
     */
    @Column(name = "module", length = 100, nullable = false)
    private String module;

    /**
     * 操作类型
     */
    @Column(name = "operation", length = 100, nullable = false)
    private String operation;

    /**
     * 操作描述
     */
    @Column(name = "description", length = 500)
    private String description;

    /**
     * 日志类型
     */
    @Column(name = "log_type", length = 20, nullable = false)
    private String logType;

    /**
     * 请求方法
     */
    @Column(name = "method", length = 10)
    private String method;

    /**
     * 请求URL
     */
    @Column(name = "url", length = 500)
    private String url;

    /**
     * 请求参数
     */
    @Column(name = "params", columnDefinition = "TEXT")
    private String params;

    /**
     * 返回结果
     */
    @Column(name = "result", columnDefinition = "TEXT")
    private String result;

    /**
     * 操作IP
     */
    @Column(name = "ip", length = 50)
    private String ip;

    /**
     * 用户代理
     */
    @Column(name = "user_agent", length = 500)
    private String userAgent;

    /**
     * 操作状态（1-成功，0-失败）
     */
    @Column(name = "status", nullable = false)
    private Integer status;

    /**
     * 耗时（毫秒）
     */
    @Column(name = "cost_time")
    private Long costTime;

    /**
     * 错误信息
     */
    @Column(name = "error_msg", columnDefinition = "TEXT")
    private String errorMsg;

    /**
     * 创建时间
     */
    @Column(name = "create_time", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;
}
